package com.ittable.tableshow.controller;

import com.ittable.tableshow.mapper.TableMapper;
import com.ittable.tableshow.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/table")
public class TableController {
    @Autowired
    private TableMapper tableMapper;

    @PostMapping("/show")
    public Result<List<Map<String, Object>>> showTable(String tableName,Integer tableType) {
        if (tableType == 0) {
            List<Map<String, Object>> tables = tableMapper.getTableList(tableName);
            if (tables.isEmpty()) {
                return Result.error("表 " + tableName + " 不存在");
            }else {
                return Result.success(tables);
            }
        } else if (tableType == 1) {
            List<Map<String, Object>> tables = tableMapper.getTableInfo(tableName);
            if (tables.isEmpty()) {
                return Result.error("表 " + tableName + " 不存在");
            }else {
                return Result.success(tables);
            }
        }else{
            return Result.error("指令错误");
        }

    }
}




